/*
 * @Author: yangzonglong
 * @Date: 2021-07-09 13:20:24
 * @version: v1.0.0
 * @Descripttion: table code 控制器
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-08-30 13:24:01
 * @Auditor:
 */
import React, { useCallback, } from 'react';
import { Form, Input } from 'antd';
import update from 'immutability-helper';
import CommonController from '../CommonController';
import { IProps } from '../config';

const InputController = ({
  tableProps,
  originalIndex,
  print,
  columns,
  dataIndex,
  width,
  title,
  titleEn,
  statusTransfer,
  statusTransferEn,
  disabled,
  exportFlag,
  setCurColumn,
  changeControlProps,
  fontSize,
  fontWeight,
  backgroundColor,
  color,
  customizeStyleFlag
}: IProps) => {
  const _changeControlProps = useCallback(
    (e: any, k: string, isChecked?: boolean) => {
      changeControlProps(
        'tableProps',
        {
          ...tableProps,
          columns: update(columns!, {
            [originalIndex!]: {
              [k]: {
                $set: isChecked ? e.target.checked : e.target.value,
              },
            },
          }),
        },
        true
      );

      setCurColumn?.({ ...columns![originalIndex!], originalIndex, [k]: isChecked ? e.target.checked : e.target.value });
    },
    [changeControlProps, columns, originalIndex, setCurColumn, tableProps]
  );

  return (
    <CommonController
      hideRequire
      onChangeControlProps={_changeControlProps}
      {...{ title, titleEn, dataIndex, width, print, disabled, exportFlag, fontSize, fontWeight, backgroundColor, color, customizeStyleFlag }}
    >

      <Form.Item label="状态对象">
        <Input.TextArea value={statusTransfer} onChange={(e => _changeControlProps(e, 'statusTransfer'))} />
      </Form.Item>

      <Form.Item label="状态对象(英文)">
        <Input.TextArea value={statusTransferEn} onChange={(e => _changeControlProps(e, 'statusTransferEn'))} />
      </Form.Item>
    </CommonController>
  );
};

export default InputController;
